/*
  The <pic.h> header file defines the PIC - ("Programmable Interrupt Controller" on an Intel 386 like system) handling functions.
  The PIC is the chip called 8259
*/

#ifndef _PIC_H
#define _PIC_H

#include <types.h>

/* IRQs related constants */

/* Map significative names to IRQs numbers */

#define IRQ_TIMER                0
#define IRQ_KEYBOARD             1
#define IRQ_CASCADE              2      /* connected to slave PIC */
#define IRQ_RS232_2              3
#define IRQ_RS232_1              4
#define IRQ_PRINTER              5
#define IRQ_FLOPPY               6
#define IRQ_ETHERNET             7
#define IRQ_CLOCK                8
#define IRQ_09                   9      /* unnamed */
#define IRQ_10                  10      /* unnamed */
#define IRQ_11                  11      /* unnamed */
#define IRQ_PS2MOUSE            12
#define IRQ_FPU                 13
#define IRQ_IDE_0               14
#define IRQ_IDE_1               15


/* Hardware I/O Ports */

/* PICs - 8259 interrupt controller ports */
#define PIC_8259M_CTRL          0x20    /* I/O port for Master PIC */
#define PIC_8259M_MASK          0x21    /* port for masking interrupts of Master PIC */
#define PIC_8259S_CTRL          0xA0    /* I/O port for Slave PIC */
#define PIC_8259S_MASK          0xA1    /* port for masking interrupts of Slave PIC */

/* Magic numbers for PICs */

#define IRQ_EOI                 0x20    /* EOI command */
#define IRQ_NUM                 16      /* there are 16 IRQs */


/* Functions */

extern void reprogram_PICs(void);
extern void irq_enable(int n);
extern void irq_disable(int n);
extern void irq_enable_all(void);
extern void irq_disable_all(void);

extern void send_specific_EOI(byte_t irq_num);
extern void send_EOI(void);
extern int spurious_IRQ(int n);

#endif /* _PIC_H */
